# -*- coding: utf-8 -*-
from model import Collection, db


class Comment(Collection):
    '''
* `_id` (ObjectId) - Object ID of comment
* `fromUserId` (string) - 评论者的 ID
* `toUserId` (string) - 被回复者的 ID (可能为空)
* `content` (string) - content of comment
* `timestamp` (long) - timestamp of comment
* `problemId` (string) - 这条评论是哪个问题下的
    '''

    collection = db.comment

    class Field(object):
        _id = '_id'
        fromUserId = 'fromUser'
        toUserId = 'toUserId'
        content = 'content'
        timestamp = 'timestamp'
        problemId = 'problemId'

    @staticmethod
    def new_comment(from_user, to_user, content, timestamp, problem_id):
        return Comment.insert({
            Comment.Field.fromUserId: from_user,
            Comment.Field.toUserId: to_user,
            Comment.Field.content: content,
            Comment.Field.timestamp: timestamp,
            Comment.Field.problemId: problem_id
        })
